/**
 * @file binary_tree.h
 * Definition file for a generic BinaryTree data structure
 * @author Denis Ollier
 * @ingroup BinaryTree
 */

#ifndef BINARY_TREE_H
#define BINARY_TREE_H

#include <yadl_common.h>

/** A node of the BinaryTree */
struct binary_node {
	/** The element of the binary_node */
	void* element;
	/** The child lesser than the binary_node */
	struct binary_node* left_child;
	/** The right greater or equal than the binary_node */
	struct binary_node* right_child;
};

/** The generic BinaryTree data structure */
struct binary_tree {
	/** The root of the BinaryTree */
	struct binary_node* root;
	/** A comparator between two elements of the BinaryTree */
	comparator_t elements_comparator;
	/** A destructor for the elements of the BinaryTree */
	destructor_t element_destructor;
};

/** The BinaryTree object */
typedef struct binary_tree* binary_tree;

/**
 *
 * @param tree
 * @param element
 * @retval 0
 * @retval 1
 */
unsigned int binary_tree_insert_element(binary_tree tree, const void* element);

/**
 *
 * @param elements_comparator
 * @param element_destructor
 * @return
 * @retval NULL
 */
binary_tree binary_tree_new(comparator_t elements_comparator, destructor_t element_destructor);

/**
 *
 * @param tree
 * @param element
 * @retval 0
 * @retval 1
 */
unsigned int binary_tree_remove_element(binary_tree tree, const void* element);

/**
 *
 * @param tree
 * @param element
 * @return
 * @retval NULL
 */
void* binary_tree_search_element(binary_tree tree, const void* element);

 /**
 *
 * @param tree
 * @param elements_comparator
 */
void binary_tree_set_comparator(binary_tree tree, comparator_t elements_comparator);

 /**
 *
 * @param tree
 * @param element_destructor
 */
void binary_tree_set_destructor(binary_tree tree, destructor_t element_destructor);

#endif /* BINARY_TREE_H */
